<template>
  <div>
    <el-card :bordered="false" shadow="never" class="ivu-mb-16" :body-style="{ padding: 0 }">
      <div class="padding-add">
        <el-form
          ref="formValidate"
          :model="formValidate"
          label-width="75px"
          label-position="right"
          class="tabform"
          @submit.native.prevent
        >
          <el-form-item label="时间选择：">
            <el-radio-group
              v-model="formValidate.date"
              type="button"
              @change="selectChange(formValidate.date)"
              class="mr"
            >
              <el-radio-button
                :label="item.val"
                v-for="(item, i) in fromList.fromTxt"
                :key="i"
              >{{ item.text }}</el-radio-button>
            </el-radio-group>
            <el-date-picker
              @change="onchangeTime"
              value-format="yyyy/MM/dd"
              v-model="timeVal"
              format="yyyy/MM/dd"
              type="daterange"
              placement="bottom-end"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="提现状态：">
            <el-radio-group
              type="button"
              v-model="formValidate.status"
              class="mr15"
              @change="selChange"
            >
              <el-radio-button
                :label="itemn.value"
                v-for="(itemn, indexn) in treeData.withdrawal"
                :key="indexn"
              >
                {{
                itemn.title
                }}
              </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="提现方式：">
            <el-radio-group
              type="button"
              v-model="formValidate.extractType"
              class="mr15"
              @change="selChange"
            >
              <el-radio-button
                :label="itemn.value"
                v-for="(itemn, indexn) in treeData.payment"
                :key="indexn"
              >
                {{
                itemn.title
                }}
              </el-radio-button>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="搜索：">
            <div class="acea-row row-middle">
              <el-input
                placeholder="微信昵称/姓名/支付宝账号/银行卡号"
                element-id="name"
                v-model="formValidate.nireid"
                style="width: 30%"
              >
                <el-button type="primary" slot="append" @click="selChange" icon="el-icon-search"></el-button>
              </el-input>
            </div>
          </el-form-item>
          
        </el-form>
      </div>
    </el-card>
    <!-- <cards-data :cardLists="cardLists" v-if="extractStatistics"></cards-data> -->
    <el-card :bordered="false" shadow="never">
      <el-table ref="table" :data="tabList" v-loading="loading" empty-text="暂无数据" class="mt14">
        <el-table-column label="ID" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>

        <el-table-column label="提现金额" min-width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.extractPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column label="提现方式" min-width="130">
          <template slot-scope="scope">
            <div class="type" v-if="scope.row.extractType === 'bank'">
              <div class="item">姓名:{{ scope.row.realName }}</div>
              <div class="item">银行卡号:{{ scope.row.bankCode }}</div>
              <div class="item">银行开户地址:{{ scope.row.bankAddress }}</div>
            </div>
            <div class="type" v-if="scope.row.extractType === 'wx'">
              <div class="item">姓名:{{ scope.row.realName }}</div>
              <div class="item">微信号:{{ scope.row.wechat }}</div>
            </div>
            <div class="type" v-if="scope.row.extractType === 'alipay'">
              <div class="item">姓名:{{ scope.row.realName }}</div>
              <div class="item">支付宝号:{{ scope.row.alipayCode }}</div>
            </div>
            <div class="type" v-if="scope.row.extractType === 'balance'">
              <div class="item">姓名:{{ scope.row.realName }}</div>
              <div class="item">提现方式：佣金转入余额</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="收款码" min-width="90">
          <template slot-scope="scope">
            <div
              class="tabBox_img"
              v-viewer
              v-if="scope.row.extractType === 'wx' || scope.row.extractType === 'alipay'"
            >
            <el-image :src="scope.row.qrcodeUrl" :preview-src-list="[scope.row.qrcodeUrl]" />
              
            </div>
          </template>
        </el-table-column>
        <el-table-column label="申请时间" min-width="130">
          <template slot-scope="scope">
            <span>{{ scope.row.addTimeStr }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="130">
          <template slot-scope="scope">
            <span>{{ scope.row.mark }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" min-width="130">
          <template slot-scope="scope">
            <div class="status" v-if="scope.row.status === 0">
              <div class="statusVal">申请中</div>
              <div></div>
            </div>
            <div class="statusVal" v-if="scope.row.status === 1">提现通过</div>
            <div class="statusVal" v-if="scope.row.status === -1">
              提现未通过
              <br />
              未通过原因：{{ scope.row.failMsg }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="170">
          <template slot-scope="scope" v-if="scope.row.status == 0">
            <a class="item" v-db-click @click="adopt(scope.row, '审核通过', index)">通过</a>
            <el-divider direction="vertical"></el-divider>
            <a class="item" v-db-click @click="invalid(scope.row)">驳回</a>
          </template>
        </el-table-column>
      </el-table>
      <div class="acea-row row-right page">
        <el-pagination
          v-if="total"
          :total="total"
          :current-page="formValidate.page"
          :page-size="formValidate.limit"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!-- 拒绝通过-->
    <el-dialog :visible.sync="modals" title="未通过原因" :close-on-click-modal="false" width="540px">
      <el-input v-model="failMsg.message" type="textarea" :rows="4" placeholder="请输入未通过原因" />
      <div slot="footer">
        <el-button type="primary" size="small" v-db-click @click="oks">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
    <script>
import { getAgentExtractListApi, agentCashEditApi, agentExtractAdoptApi, agentExtractRefuseApi } from '@/api/base';
import { formatDate } from '@/utils/validate';
export default {
  name: 'cashApply',
  filters: {
    formatDate(time) {
      if (time !== 0) {
        let date = new Date(time * 1000);
        return formatDate(date, 'yyyy-MM-dd hh:mm');
      }
    },
  },
  data() {
    return {
      images: ['1.jpg', '2.jpg'],
      modal_loading: false,
      failMsg: {
        message: '输入信息不完整或有误!',
      },
      adoptModals: false,
      cash_table: {
        id: '',
      },
      fromList: {
        title: '选择时间',
        custom: true,
        fromTxt: [
          { text: '全部', val: '' },
          { text: '今天', val: 'today' },
          { text: '昨天', val: 'yesterday' },
          { text: '本周', val: 'week' },
          { text: '本月', val: 'month' },
          { text: '本季度', val: 'quarter' },
          { text: '本年', val: 'year' },
        ],
      },
      modals: false,
      total: 0,
      cardLists: [],
      loading: false,
      tabList: [],
      pickerOptions: this.$timeOptions,
      treeData: {
        withdrawal: [
          {
            title: '全部',
            value: '',
          },
          {
            title: '未通过',
            value: -1,
          },
          {
            title: '申请中',
            value: 0,
          },
          {
            title: '已通过',
            value: 1,
          },
        ],
        payment: [
          {
            title: '全部',
            value: '',
          },
          {
            title: '微信',
            value: 'wx',
          },
          {
            title: '支付宝',
            value: 'alipay',
          },
          {
            title: '银行卡',
            value: 'bank',
          },
        ],
      },
      formValidate: {
        status: '',
        extractType: '',
        nireid: '',
        date: '',
        page: 1,
        limit: 20,
      },
      extractStatistics: {},
      timeVal: [],
      FromData: null,
      extractId: 0,
    };
  },
  watch: {
    // $route() {
    //   if (this.$route.fullPath === this.$routeProStr + '/finance/user_extract/index?status=0') {
    //     this.getPath();
    //   }
    // },
  },
  mounted() {
    this.getList();
  },
  methods: {
    getPath() {
      this.formValidate.page = 1;
      this.formValidate.status = parseInt(this.$route.query.status);
      this.getList();
    },
    // 无效
    invalid(row) {
      this.extractId = row.id;
      this.modals = true;
    },
    // 具体日期
    onchangeTime(e) {
      console.log(e);
      this.timeVal = e;
      this.formValidate.date = this.timeVal ? this.timeVal.join('-') : '';
      this.formValidate.page = 1;
      this.getList();
    },
    // 选择时间
    selectChange(tab) {
      this.formValidate.page = 1;
      this.formValidate.date = tab;
      this.timeVal = [];
      this.getList();
    },
    // 选择
    selChange() {
      this.formValidate.page = 1;
      this.getList();
    },
    // 确定
    oks() {
      this.modal_loading = true;
      agentExtractRefuseApi({ id: this.extractId, failMsg: this.failMsg.message })
        .then(async (res) => {
          this.$message.success('操作成功');
          this.modal_loading = false;
          this.modals = false;
          this.getList();
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    // 通过
    adopt(row, tit, num) {
      this.$confirm('确认审核通过', '提现审核').then(() => {
        agentExtractAdoptApi({ id: row.id }).then((res) => {
          console.log(res);
          this.$message.success('操作成功');
          this.getList();
        });
      });
    },
    // 列表
    getList() {
      this.loading = true;
      getAgentExtractListApi(this.formValidate)
        .then(async (res) => {
          let data = res;
          this.tabList = data.list.list;
          this.total = data.list.count;
          this.extractStatistics = data.extract_statistics;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$message.error(res.msg);
        });
    },
    // 编辑
    edit(row) {
      agentCashEditApi(row.id)
        .then(async (res) => {
          if (res.data.status === false) {
            return this.$authLapse(res.data);
          }
          this.FromData = res.data;
          this.$refs.edits.modals = true;
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    // 编辑提交成功
    submitFail() {
      this.getList();
    },
    pageChange(e) {
      this.formValidate.page = e;
      this.getList();
    },
  },
};
</script>
    <style scoped lang="stylus">
    .ivu-mt .type .item {
      margin: 3px 0;
    }

    .tabform {
      margin-bottom: 10px;
    }

    .Refresh {
      font-size: 12px;
      color: var(--prev-color-primary);
      cursor: pointer;
    }

    .ivu-form-item {
      margin-bottom: 10px;
    }

    .status ::v-deep .item~.item {
      margin-left: 6px;
    }

    .status ::v-deep .statusVal {
      margin-bottom: 7px;
    }

    /* .ivu-mt ::v-deep .ivu-table-header */
    /* border-top:1px dashed #ddd!important */
    .type {
      padding: 3px 0;
      box-sizing: border-box;
    }

    .tabBox_img {
      width: 36px;
      height: 36px;
      border-radius: 4px;
      cursor: pointer;

      img {
        width: 100%;
        height: 100%;
      }
    }
</style>
    